package dao;

import org.hibernate.Session;
import org.hibernate.Transaction;
import connection.connectionFactory;
import model.Opcao;

public class OpcaoDao {
           
    Session session;
    Transaction tx; 
    
    public void salvar(Opcao opcao)
    {
      try
      {
          session = new connectionFactory().getSessionFactory();
          tx =  session.beginTransaction();
          session.save(opcao);
          tx.commit();
          session.close();
            
      }
      catch(Exception e)
      {
           e.printStackTrace();
           tx.rollback();
           session.close();
      }
    } 
    
    public void alterar(Opcao opcao)
    {
      try
      {
          session = new connectionFactory().getSessionFactory();
          tx =  session.beginTransaction();
          session.update(opcao);
          tx.commit();
          session.close();
            
      }
      catch(Exception e)
      {
           e.printStackTrace();
           tx.rollback();
           session.close();
      }
    }  
    
    public void excluir(Opcao opcao)
    {
      try
      {
          session = new connectionFactory().getSessionFactory();
          tx =  session.beginTransaction();
          session.delete(opcao);
          tx.commit();
          session.close();
            
      }
      catch(Exception e)
      {
           e.printStackTrace();
           tx.rollback();
           session.close();
      }
    } 
}

